<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script>
    window.onload = function add() {

        let btn1 = document.querySelector(".btn");
        btn1.onclick = function () {
            let name = document.getElementById("name").value;
            let age = document.getElementById("age").value;
            let height = document.getElementById("height").value;
            let school = document.getElementById("school").value;
            let xmlHttp = new XMLHttpRequest();
            xmlHttp.open("get", '/lodinweb2_0_war_exploded/crud?type=add&name=' + name + '&age=' + age + '&height=' + height + '&school=' + school, true);
            xmlHttp.send();
            xmlHttp.onreadystatechange = function () {
                //4.响应数据成功
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    //5.写入数据
                    let data = xmlHttp.responseText;
                    if (data == "addok") {
                        window.location.href = "student.html"
                    }
                }
            }
        }
    }
</script>
<body style='background:pink'>

<div class="form-group">
    <label for="name">name</label>
    <input type="text" class="form-control" name="name" id="name" placeholder="请输入name,注意这是唯一嗷">
</div>
<div class="form-group">
    <label for="name">age</label>
    <input type="text" class="form-control" name="age" id="age" placeholder="请输入age">
</div>
<div class="form-group">
    <label for="name">height</label>
    <input type="text" class="form-control" name="height" id="height" placeholder="请输入height">
</div>
<div class="form-group">
    <label for="name">school</label>
    <input type="text" class="form-control" name="school" id="school" placeholder="请输入school">
</div>
<button class="btn">添加</button>

</div>
</body>
</html>